#-------------------------------------------------------------------
# This file is part of the CMake build system for OGRE
#     (Object-oriented Graphics Rendering Engine)
# For the latest info, see http://www.ogre3d.org/
#
# The contents of this file are placed in the public domain. Feel
# free to make use of it in any way you like.
#-------------------------------------------------------------------

# - Try to find LUA
# Once done, this will define
#
#  LUA_FOUND - system has LUA
#  LUA_INCLUDE_DIRS - the LUA include directories
#  LUA_LIBRARIES - link these to use LUA

include(FindPkgMacros)
findpkg_begin(LUA)

# Get path, convert backslashes as ${ENV_${var}}
getenv_path(LUA_HOME)

# construct search paths
set(LUA_PREFIX_PATH ${LUA_HOME} ${ENV_LUA_HOME})
create_search_paths(LUA)
# redo search if prefix path changed
clear_if_changed(LUA_PREFIX_PATH
  LUA_LIBRARY_FWK
  LUA_LIBRARY_REL
  LUA_LIBRARY_DBG
  LUA_INCLUDE_DIR
)

set(LUA_LIBRARY_NAMES lua5.1)
get_debug_names(LUA_LIBRARY_NAMES)

use_pkgconfig(LUA_PKGC lua5.1)

findpkg_framework(LUA)

find_path(LUA_INCLUDE_DIR NAMES lua.h lua.hpp HINTS ${LUA_INC_SEARCH_PATH} ${LUA_PKGC_INCLUDE_DIRS})
find_library(LUA_LIBRARY_REL NAMES ${LUA_LIBRARY_NAMES} HINTS ${LUA_LIB_SEARCH_PATH} ${LUA_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" release relwithdebinfo minsizerel)
find_library(LUA_LIBRARY_DBG NAMES ${LUA_LIBRARY_NAMES_DBG} HINTS ${LUA_LIB_SEARCH_PATH} ${LUA_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" debug)
make_library_set(LUA_LIBRARY)

findpkg_finish(LUA)

